package com.dgut.admodule.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dgut.admodule.entity.Adsbid;
import com.dgut.admodule.entity.dto.AdsbidAddDTO;
import com.dgut.admodule.entity.dto.AdsbidQueryDTO;
import com.dgut.admodule.service.IAdsbidService;
import com.dgut.common.util.ExtAjaxResponse;
import com.dgut.common.util.ExtPageable;

@Controller
@RequestMapping("/adsbid")
public class AdsbidController {
	@Autowired
	private IAdsbidService adsbidService;
	
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(AdsbidAddDTO adsbidAddDTO) {
		try {
			adsbidService.saveOrUpdate(adsbidAddDTO);
			return new ExtAjaxResponse(true,"参与竞价成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(@RequestParam Long id) 
	{
		try {
			Adsbid adsbid =  adsbidService.findOne(id);
			if(null!=adsbid) {
				adsbidService.delete(adsbid);
			}
			return new ExtAjaxResponse(true,"删除成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败！");
		}
	}
	
	@RequestMapping("/deleteAdsbids")
	public @ResponseBody ExtAjaxResponse deleteStaffs(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				adsbidService.delete(idLists);
			}
			return new ExtAjaxResponse(true,"删除成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败！");
		}
	}
	
	@RequestMapping("/findOne")
	public @ResponseBody Adsbid findOne(@RequestParam Long id) 
	{
		Adsbid adsbid =  adsbidService.findOne(id);
		
		return adsbid;
	}
	
	@RequestMapping("/findCompany")
	public @ResponseBody Adsbid findCompany(@RequestParam String cName) 
	{
		Adsbid adsbid =  adsbidService.findCompany(cName);
		
		return adsbid;
	}
	
	@RequestMapping("/findByBid")
	public @ResponseBody List<Adsbid> findByBid(@RequestParam Long bidId) 
	{
		 List<Adsbid> lists =  adsbidService.findByBid(bidId);
		
		return lists;
	}
	
	@RequestMapping("/findAll")
	public @ResponseBody List<Adsbid> findAll() 
	{
		 List<Adsbid> lists =  adsbidService.findAll();
		
		return lists;
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page<Adsbid> findPage(AdsbidQueryDTO adsbidQueryDTO,ExtPageable pageable) 
	{
		Page<Adsbid> page =  adsbidService.findAll(AdsbidQueryDTO.getSpecification(adsbidQueryDTO), pageable.getPageable());
		
		return page;
	}
}
